/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package foxmob.mlts.view.student;

import foxmob.mlts.view.*;
import foxmob.mlts.model.MultipleChoiceQuestion;
import foxmob.mlts.model.Question;
import foxmob.mlts.viewcontroller.student.QuestionPaperForm;

/**
 *
 * @author zpf16z
 */
public class MultipleChoicePanel extends javax.swing.JPanel {

    MultipleChoiceQuestion mcq = new MultipleChoiceQuestion();
    int questionSection;
    int questionSubsection;
    int questionNuber;
    boolean state = false;
    /**
     * Creates new form MultipleChoicePanel
     */
    public MultipleChoicePanel() {
        initComponents();
    }
    public void loadQuestionContent(MultipleChoiceQuestion question, int count){
        this.mcq = question;
//        this.questionSection = qSection;
//        this.questionSubsection = qSubsection;
        this.questionNuber = count;
        try {
            //this.jLabelQuestionID.setText(question.getID().toString());
            this.jLabelQuestionID.setText("Q" + Integer.toString(count) + ":");
            this.jLabelQuestion.setText(question.getQuestionText());
            this.jRadioButtonAnswer1.setText(question.getPossibleAnswers()[0]);
            this.jRadioButtonAnswer2.setText(question.getPossibleAnswers()[1]);
            this.jRadioButtonAnswer3.setText(question.getPossibleAnswers()[2]);
            this.jRadioButtonAnswer4.setText(question.getPossibleAnswers()[3]);
            //this.jRadioButtonAnswer1.setText(question.getPossibleAnswers()[0]);
        } catch (Exception e) {
           // 
        }
        return;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupPossibleAnswers = new javax.swing.ButtonGroup();
        jLabelQuestionID = new javax.swing.JLabel();
        jLabelQuestion = new javax.swing.JLabel();
        jRadioButtonAnswer1 = new javax.swing.JRadioButton();
        jRadioButtonAnswer2 = new javax.swing.JRadioButton();
        jRadioButtonAnswer3 = new javax.swing.JRadioButton();
        jRadioButtonAnswer4 = new javax.swing.JRadioButton();
        jLabelSpaceTaker = new javax.swing.JLabel();

        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabelQuestionID.setText("Q1.");
        add(jLabelQuestionID, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, 20));

        jLabelQuestion.setText("This is a question!!!!!!!!!!!!!!!!!!!!!!");
        add(jLabelQuestion, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 10, -1, 20));

        buttonGroupPossibleAnswers.add(jRadioButtonAnswer1);
        jRadioButtonAnswer1.setText("Answer1");
        jRadioButtonAnswer1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonAnswer1ActionPerformed(evt);
            }
        });
        add(jRadioButtonAnswer1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 50, -1, -1));

        buttonGroupPossibleAnswers.add(jRadioButtonAnswer2);
        jRadioButtonAnswer2.setText("Answer2");
        jRadioButtonAnswer2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonAnswer2ActionPerformed(evt);
            }
        });
        add(jRadioButtonAnswer2, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 80, -1, -1));

        buttonGroupPossibleAnswers.add(jRadioButtonAnswer3);
        jRadioButtonAnswer3.setText("Answer3");
        jRadioButtonAnswer3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonAnswer3ActionPerformed(evt);
            }
        });
        add(jRadioButtonAnswer3, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 110, -1, -1));

        buttonGroupPossibleAnswers.add(jRadioButtonAnswer4);
        jRadioButtonAnswer4.setText("Answer4");
        jRadioButtonAnswer4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonAnswer4ActionPerformed(evt);
            }
        });
        add(jRadioButtonAnswer4, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 140, -1, -1));

        jLabelSpaceTaker.setText("    ");
        add(jLabelSpaceTaker, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 170, 30, 20));
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButtonAnswer1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonAnswer1ActionPerformed
        // TODO add your handling code here:
        setAnswer(1);
        setQusetionFinished();
    }//GEN-LAST:event_jRadioButtonAnswer1ActionPerformed

    private void jRadioButtonAnswer2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonAnswer2ActionPerformed
        // TODO add your handling code here:
        setAnswer(2);
        setQusetionFinished();
    }//GEN-LAST:event_jRadioButtonAnswer2ActionPerformed

    private void jRadioButtonAnswer3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonAnswer3ActionPerformed
        // TODO add your handling code here:
        setAnswer(3);
        setQusetionFinished();
    }//GEN-LAST:event_jRadioButtonAnswer3ActionPerformed

    private void jRadioButtonAnswer4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonAnswer4ActionPerformed
        // TODO add your handling code here:
        setAnswer(4);
        setQusetionFinished();
    }//GEN-LAST:event_jRadioButtonAnswer4ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupPossibleAnswers;
    private javax.swing.JLabel jLabelQuestion;
    private javax.swing.JLabel jLabelQuestionID;
    private javax.swing.JLabel jLabelSpaceTaker;
    private javax.swing.JRadioButton jRadioButtonAnswer1;
    private javax.swing.JRadioButton jRadioButtonAnswer2;
    private javax.swing.JRadioButton jRadioButtonAnswer3;
    private javax.swing.JRadioButton jRadioButtonAnswer4;
    // End of variables declaration//GEN-END:variables

    private void setAnswer(int studentAnswer) {
//        MultipleChoiceQuestion question =
//                (MultipleChoiceQuestion)QuestionPaperForm.testRecord.getAllQuestions().get(this.questionNuber - 1);
//        question.setStudentAnswer(studentAnswer);
        mcq.setStudentAnswer(studentAnswer);
    }
    
    public void setMCQ(MultipleChoiceQuestion multipleChoiceQuestion){
        this.mcq = multipleChoiceQuestion;
    }
    public MultipleChoiceQuestion getMCQ(){
        return this.mcq;
    }
    
    public boolean isAnswered(){
        return this.state;
    }
    
    public void setQusetionFinished(){
        if(this.state == false){
            QuestionPaperForm.finishedQuestions ++;
            this.state = true;
            //StudentsForm
        }else{
        //
        }
    }
}